%% randomDiscrete.m
%  This function simulates from a discrete distribution

function y = randomDiscrete(p)

nSupp = size(p,1);
nVar = size(p,2);
uniformDraws = ones(nSupp-1,1)*unifrnd(0,1,[1, nVar]);
cumulativeP = cumsum(p);
y = sum([ones(1,nVar);cumulativeP(1:nSupp-1,:)<=uniformDraws]);
